package utils

import (
	"fmt"
	"reflect"
	"regexp"
)

func IsEmpty(strs ...string) bool {
	for _, str := range strs {
		if len(str) == 0 {
			return true
		}
	}
	return false
}

func IsObjNil(args ...interface{}) bool {
	for _, obj := range args {
		if obj == nil {
			return true
		}
	}
	return false
}

func IsStrValid(str, pattern string) bool {
	re := regexp.MustCompile(pattern)
	return re.MatchString(str)
}

func ContainKey(m, key interface{}) (bool, error) {
	val := reflect.ValueOf(m)
	if val.Kind() != reflect.Map {
		return false, fmt.Errorf("参数不是Map类型")
	}
	keyVal := reflect.ValueOf(key)
	res := val.MapIndex(keyVal)
	return res.IsValid(), nil
}
